home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / programr / atre27.exe / ATREE_27 / MOSQWIN / MOSQUITO.C < prev    next >
C/C++ Source or Header  |  1992-08-01  |  6KB  |  192 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** mosquito.c                                                          ****
  4.  **** atree release 2.7 for Windows                                       ****
  5.  **** Adaptive Logic Network (ALN) simulation program.                    ****
  6.  **** Copyright (C) A. Dwelly, R. Manderscheid, M. Thomas, W.W. Armstrong ****
  7.  ****               1991, 1992                                            ****
  8.  **** License:                                                            ****
  9.  **** A royalty-free license is granted for the use of this software for  ****
  10.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ****
  11.  **** modified provided this notice appears in its entirety and unchanged ****
  12.  **** in all derived source programs.  Persons modifying the code are     ****
  13.  **** requested to state the date, the changes made and who made them     ****
  14.  **** in the modification history.                                        ****
  15.  ****                                                                     ****
  16.  **** Patent License:                                                     ****
  17.  **** The use of a digital circuit which transmits a signal indicating    ****
  18.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  19.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  20.  **** W. W. Armstrong, President.  A royalty-free license is granted      ****
  21.  **** by the company to use this patent for NON_COMMERCIAL PURPOSES to    ****
  22.  **** adapt logic trees using this program and its modifications.         ****
  23.  ****                                                                     ****
  24.  **** Limited Warranty:                                                   ****
  25.  **** This software is provided "as is" without warranty of any kind,     ****
  26.  **** either expressed or implied, including, but not limited to, the     ****
  27.  **** implied warrantees of merchantability and fitness for a particular  ****
  28.  **** purpose.  The entire risk as to the quality and performance of the  ****
  29.  **** program is with the user.  Neither the authors, nor the             ****
  30.  **** University of Alberta, its officers, agents, servants or employees  ****
  31.  **** shall be liable or responsible in any way for any damage to         ****
  32.  **** property or direct personal or consequential injury of any nature   ****
  33.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  34.  **** or any other party as a consequence of the use or disposition of    ****
  35.  **** this software.                                                      ****
  36.  ****                                                                     ****
  37.  **** Modification history:                                               ****
  38.  ****                                                                     ****
  39.  **** 5.9.90 Initial implementation, A.Dwelly                             ****
  40.  **** 31.5.91 Windows Port & Windows Extensions, M. Thomas                ****
  41.  **** 91.07.17 atree v2.0 for Windows, M. Thomas                          ****
  42.  **** 92.04.27 atree v2.5 for Windows, M. Thomas                          ****
  43.  **** 92.03.07 Release 2.6, Monroe Thomas                                 ****
  44.  **** 92.01.08 Release 2.7, Monroe Thomas                                 ****
  45.  ****                                                                     ****
  46.  *****************************************************************************/
  47.  
  48. #include <windows.h>
  49. #include "atree.h"
  50.  
  51. #define VERBOSITY 0
  52. #define TRAINSETSIZE 500
  53. #define WIDTH 80
  54. #define TREESIZE 256
  55. #define TESTSIZE 500
  56.  
  57. #define BITTEN 1
  58. #define QUININE 7
  59. #define ANEMIA 12
  60.  
  61. #define Printf(str,fmt1,fmt2) \
  62.             { \
  63.             char Buff[80]; \
  64.             sprintf(Buff, str, fmt1, fmt2); \
  65.             MessageBox(hwnd, Buff, "Mosquito", MB_OK); \
  66.             }
  67.  
  68. BOOL quit_flag;
  69.  
  70. char mosquito(v)
  71.  
  72. char *v;
  73.  
  74. {
  75.     return(v[BITTEN] && (!v[QUININE]) && (!v[ANEMIA]));
  76. }
  77.  
  78. BOOL NEAR PASCAL main(HWND hwnd, HANDLE hInstance)
  79.  
  80. {
  81.     int i;
  82.     int j;
  83.     int malaria = 0;
  84.     int healthy = 0;
  85.     char vec[WIDTH];
  86.     char ui[1];
  87.     int correct = 0;
  88.     LPBIT_VEC training_set;
  89.     LPBIT_VEC icres;
  90.     LPBIT_VEC test;
  91.     LPATREE tree;
  92.     HCURSOR hCursor;
  93.  
  94.     /* Initialise */
  95.  
  96.     quit_flag = FALSE;
  97.  
  98.     training_set = (LPBIT_VEC) Malloc(TRAINSETSIZE * sizeof(bit_vec));
  99.     MEMCHECK(training_set);
  100.  
  101.     icres = (LPBIT_VEC) Malloc(TRAINSETSIZE * sizeof(bit_vec));
  102.     MEMCHECK(icres);
  103.  
  104.     atree_init(hInstance, hwnd);
  105.  
  106.     /* Create the test data */
  107.  
  108.     for (i = 0; i < TRAINSETSIZE; i++)
  109.     {
  110.         /* allow multitasking during long loop! */
  111.         Windows_Interrupt(1500);
  112.  
  113.         if (quit_flag) exit(0);
  114.  
  115.         for (j = 0; j < WIDTH; j++)
  116.         {
  117.             vec[j] = (char)RANDOM(2);
  118.         }
  119.         training_set[i] = *(bv_pack(vec, WIDTH));
  120.         ui[0] = mosquito(vec);
  121.         if (ui[0])
  122.         {
  123.             malaria++;
  124.         }
  125.         else
  126.         {
  127.             healthy++;
  128.         }
  129.         icres[i] = *(bv_pack(ui,1));
  130.     }
  131.  
  132.     Printf("There are %d patients with malaria, and %d healthy in the training set\n",malaria,healthy);
  133.  
  134.     if (quit_flag) exit(0);
  135.  
  136.     /* Create a tree and train it */
  137.  
  138.     tree = atree_create(WIDTH,TREESIZE);
  139.     (void) atree_train(tree,training_set,icres,0,TRAINSETSIZE,
  140.                        TRAINSETSIZE-1,10,1);
  141.  
  142.     if (quit_flag) exit(0);
  143.  
  144.    /* Test the trained tree */
  145.  
  146.     for (i = 0; i < TESTSIZE; i++)
  147.     {
  148.         /* allow multitasking during long loop! */
  149.         Windows_Interrupt(1500);
  150.  
  151.         if (quit_flag) exit(0);
  152.  
  153.         for (j = 0; j < WIDTH; j++)
  154.         {
  155.             vec[j] = RANDOM(2);
  156.         }
  157.         test = bv_pack(vec,WIDTH);
  158.         if (atree_eval(tree,test) == mosquito(vec))
  159.         {
  160.             correct++;
  161.         }
  162.         bv_free(test);
  163.     }
  164.  
  165.     if (quit_flag) exit(0);
  166.  
  167.     Printf("%d correct out of %d in final test\n",correct,TESTSIZE);
  168.  
  169.     /* Discard training set */
  170.  
  171.     hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  172.     ShowCursor(TRUE);
  173.  
  174.     for (i = 0; i < TRAINSETSIZE; i++)
  175.     {
  176.         Free(training_set[i].bv);
  177.         Free(icres[i].bv);
  178.     }
  179.  
  180.     Free(training_set);
  181.     Free(icres);
  182.  
  183.     ShowCursor(FALSE);
  184.     SetCursor(hCursor);
  185.  
  186.     /* Discard tree */
  187.     atree_free(tree);
  188.     atree_quit();
  189.  
  190.     return(1);
  191. }
  192.